package core

class DocumentTypeController {
	
	static layout= 'general'

    def index() {
 
		def max = params.long('max')?:10
 
		def start = params.long('start')?:1
 
		render(view:'index', model : [documentType: DocumentType.list(max: max, offset:start)])
 
	}
	def create() {
		
	}
 
	def show() {
 
		[documentType: DocumentType.get(params.long('id'))]
 
	}
 
	def save(){
 

 
		def documentType = new DocumentType(params)
 
		if (documentType.save()) {
 
			flash.notice = "Document type: ${documentType.name} was saved"
 
			redirect(action: 'index')
 
		}
 
		else {
 
			flash.error = "Document type: ${documentType.name} failed to be saved"
 
			render(view:'create', model:[documentType: documentType])
 
		}
 
	}
 

 
	//================================================================================
 
	def update() {
 
		def documentType =  DocumentType.get(params.long('id')) 
 
		documentType.properties = params
 
		if(documentType.save()) {
 
			flash.notice = "Document type: ${documentType.name} was updated"
 
			redirect action:'index'
 
		}
 
		else {
 
			flash.error = "Document type:  failed to be update"
 
			render(view:'edit',model:[documentType: documentType])
 
		}
 
	}
 

 
	def delete(){
 

 
		def doc = DocumentType.get(params.id)
 
		doc.delete()
 
		redirect(action:"index")
 
	}
 

 
	def edit(){
 

 
		[documentType: DocumentType.get(params.long('id'))]
 

 

 
	}
 
} 
